#!/bin/bash
# ROOT 配置修改文件

##################begin  配置区#####################
# 记录日志
DIR=/config/init
# 配置文件
CONFIG_FILE1=/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/application.properties
##################end 配置区#######################

function CONFIG_FILE1_exsit()
{
env | grep "DB_HOST" || export DB_HOST="mysql.server"
    sed -i "s#DB_HOST#$DB_HOST#g" $CONFIG_FILE1
    echo "DB_HOST replace $DB_HOST -> $CONFIG_FILE1" >> $DIR/change.log

env | grep "DB_NAME" || export DB_NAME="webtv_test"
    sed -i "s#DB_NAME#$DB_NAME#g" $CONFIG_FILE1
    echo "DB_NAME replace $DB_NAME -> $CONFIG_FILE1" >> $DIR/change.log

env | grep "DB_USERNAME" || export DB_USERNAME="mysql"
    sed -i "s#DB_USERNAME#$DB_USERNAME#g" $CONFIG_FILE1
    echo "DB_USERNAME replace $DB_USERNAME -> $CONFIG_FILE1" >> $DIR/change.log

env | grep "DB_PASSWORD" || export DB_PASSWORD="hqy-webtv"
    sed -i "s#DB_PASSWORD#$DB_PASSWORD#g" $CONFIG_FILE1
    echo "DB_PASSWORD replace $DB_PASSWORD -> $CONFIG_FILE1" >> $DIR/change.log

env | grep "DB_PORT" || export DB_PORT="3306"
    sed -i "s#DB_PORT#$DB_PORT#g" $CONFIG_FILE1
    echo "DB_PORT replace $DB_PORT -> $CONFIG_FILE1" >> $DIR/change.log


}
############begin 执行#################
# 判断文件是否存在
ls $CONFIG_FILE1 >/dev/null 2>&1 && CONFIG_FILE1_exsit || echo "$CONFIG_FILE1 不存在" >> $DIR/change.log